import { CircleGeometry, Color } from 'three/src/Three';
import { MeshBasicMaterial, Mesh } from "three";
import { Point } from '../../Engine';

/**
 * 圆
 */
export default class Circle extends Mesh {
    private param: {center: Point, radius: number, color: string, opacity?: number};

    /**
     * 圆形
     * @param param 圆形参数
     * @param param.center 圆心
     * @param param.radius 半径
     * @param param.color 颜色
     * @param param.opacity 透明度, 可选参数，默认为1
     * @param param.depthTest 是否开启深度测试, 可选参数，默认为false
     * @example let circleParam = {center: new GE.Point(120.17042482206521, 30.28378371066825, 10, '4326'), radius: 100, color: '#00FA9A', opacity: 0.6};
        circle = new GE.Circle(circleParam);
        app.add(circle);

        circle.setRadius(150); //设置圆形半径
        circle.setColor('#FF0000'); //设置圆形颜色
        circle.setOpacity(0.8); //设置圆形透明度
        circle.setCenter(new GE.Point(120.17242482206521, 30.28378371066825, 10, '4326')); //设置圆形中心点
     */
    constructor(param:{center: Point, radius: number, color: string, opacity?: number, depthTest?: boolean}){
        super();
        this.param = param;
    
        this.material = new MeshBasicMaterial({
            color: param.color, 
            transparent: true, 
            opacity: param.opacity || 1, 
            depthTest: param.depthTest || false, 
        });
        this.geometry  = new CircleGeometry(param.radius,50);   

        param.center.toEPSGWeb();
        this.position.set(param.center.x, param.center.y, param.center.z);
    }

    public setRadius(radius: number){
        this.param.radius = radius;
        this.geometry = new CircleGeometry(radius, 50);
    }

    public setOpacity(opacity: number){
        this.param.opacity = opacity;
        this.material['opacity'] = opacity;
        this.material['needsUpdate'] = true;
    }

    public setColor(color: string){
        this.param.color = color;
        this.material['color'] = new Color(color);
        this.material['needsUpdate'] = true;
    }

    public setCenter(center: Point){
        center.toEPSGWeb();
        this.param.center = center;
        this.position.set(center.x, center.y, center.z);
    }

    public getParam(){
        return this.param;
    }
}
